/*
    socklibpp library
    Copyright (C) 2005  Daniel K. O. <danielosmari at users.sf.net>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/


#include <socklibpp/sockcommon.h>

/**     \mainpage SOCKSTREAM Library


This is a networking library that provides abstraction for
\ref wrappers "cross-platform development" and
\ref highlevel "high-level design".

\note   Avoid using low-level platform-specific extensions. e.g. SIGPIPE signals
are set to SIG_IGN.

\section wrappers Cross-platform wrappers
These classes are small wrappers around the low-level and non-portable BSD
sockets implementation. They have small overhead, so you can use them even for
delicate tasks

        \li     socklib::base - with only 8 bytes in 32-bit systems, has almost all
                the functionality provided by the BSD-sockets; it has two
                members: socklib::base::fd, that contains the socket descriptor,
                and socklib::base::error, that contains the error code of the last
                operation.

        \li     socklib::addr_in - represents an IPv4 address. There are convenient
                methods for resolving and setting the address from strings

        \li     socklib::listener - a convenient and fast way to watch many sockets
                for readability/writeability at once

\section highlevel High level classes

        \li     socklib::basic_sockbuf, socklib::sockbuf - high-level buffers for sockets.
                They work just like an ordinary streambuf, so you can place them
                in any istream/ostream object.

        \li     socklib::basic_sockstream, socklib::sockstream - high-level streams for sockets,
                with convenient manipulators: crlf and lfcr.

\section secexamples Examples
See some \ref examples on how to use the library.
*/


/**     \page examples Examples
These examples are included in the tests subdirectory.

\li \ref httpdump - This code uses a sockstream object to resolve a web server's
address, and retrieve the requested document.

\li \ref listener - Demonstrates how to use the sock_listener class to listen
many sockets for reading.

\li \ref daytimed - A TCP daytimed server using socklib::base.

\li \ref echod - A TCP echo server using socklib::base

\li \ref streamechod - A TCP echo server, using sockstream.
*/

/**     \page httpdump HTTP-dump
        \include httpdump.cpp
*/
/**     \page listener Listener
        \include listener.cpp
*/
/**     \page daytimed daytimed
        \include daytimed.cpp
*/
/**     \page echod echod
        \include echod.cpp
*/

/**     \page streamechod Stream Echod
        \include streamechod.cpp
*/


/**
        \if dummy
*/

#ifdef WIN32
namespace socklib{
    class WinsockInit {
            WinsockInit()
            {
                    WSADATA data;
                    WSAStartup(MAKEWORD(2, 0), &data);
            }
            
            ~WinsockInit()
            {
                    WSACleanup();
            }
            
            static WinsockInit init;
    };
    
    WinsockInit WinsockInit::init;
}

#else

#include <csignal>

namespace socklib {
    class SigPipeSetup {
            sighandler_t previous;
            
            SigPipeSetup()
            {
                    previous = std::signal(SIGPIPE, SIG_IGN);
            }
            
            ~SigPipeSetup()
            {
                    std::signal(SIGPIPE, previous);
            }
            
            static SigPipeSetup init;
            
    };
    
    SigPipeSetup SigPipeSetup::init;
}

#endif

/**
        \endif
*/



